using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using Spacejock;
using System;
using System.Runtime.CompilerServices;
using System.Threading;
using yW5Lib;

namespace yWriter6
{
	public class clsPrintDailyWritingTarget
	{
		public delegate void PrintProgressEventHandler(string ProgressString);

		[CompilerGenerated]
		private PrintProgressEventHandler PrintProgressEvent;

		public event PrintProgressEventHandler PrintProgress
		{
			[CompilerGenerated]
			add
			{
				PrintProgressEventHandler printProgressEventHandler = PrintProgressEvent;
				PrintProgressEventHandler printProgressEventHandler2;
				do
				{
					printProgressEventHandler2 = printProgressEventHandler;
					PrintProgressEventHandler value2 = (PrintProgressEventHandler)Delegate.Combine(printProgressEventHandler2, value);
					printProgressEventHandler = Interlocked.CompareExchange(ref PrintProgressEvent, value2, printProgressEventHandler2);
				}
				while ((object)printProgressEventHandler != printProgressEventHandler2);
			}
			[CompilerGenerated]
			remove
			{
				PrintProgressEventHandler printProgressEventHandler = PrintProgressEvent;
				PrintProgressEventHandler printProgressEventHandler2;
				do
				{
					printProgressEventHandler2 = printProgressEventHandler;
					PrintProgressEventHandler value2 = (PrintProgressEventHandler)Delegate.Remove(printProgressEventHandler2, value);
					printProgressEventHandler = Interlocked.CompareExchange(ref PrintProgressEvent, value2, printProgressEventHandler2);
				}
				while ((object)printProgressEventHandler != printProgressEventHandler2);
			}
		}

		public void PrintDailyWritingTarget(clsProject cProject)
		{
			//Discarded unreachable code: IL_02db, IL_02f2, IL_02fd, IL_030d, IL_03db, IL_03dd, IL_03f1, IL_0413
			int num = default(int);
			int num10 = default(int);
			try
			{
				ProjectData.ClearProjectError();
				num = 2;
				int num2 = 2;
				int num3 = cProject.Wordcount();
				num2 = 3;
				DateTime wordTargetEndDate = cProject.WordTargetEndDate;
				num2 = 4;
				DateTime dateTime = cProject.WordTargetStartDate;
				num2 = 5;
				int wordTarget = cProject.WordTarget;
				num2 = 6;
				int wordCountStart = cProject.WordCountStart;
				num2 = 7;
				clsShared.cSubs.BusyMouse();
				num2 = 8;
				clsReport clsReport = new clsReport(ref clsShared.cLog, ref clsShared.cSettings, "Daily Writing Target");
				num2 = 9;
				clsReport.AddTitle();
				num2 = 10;
				clsReport.AddCentered(cProject.Title + " by " + cProject.AuthorName);
				num2 = 11;
				clsReport.AddBR(2);
				num2 = 12;
				clsReport.SetTableBorder(1);
				num2 = 13;
				clsReport.OpenTable("cellpadding=5");
				num2 = 14;
				clsReport.OpenRow();
				num2 = 15;
				clsReport.AddCell("Date");
				num2 = 16;
				clsReport.AddCell("Daily target");
				num2 = 17;
				clsReport.AddCell("Cumulative Target");
				num2 = 18;
				clsReport.AddCell("Written");
				num2 = 19;
				clsReport.AddCell("Cumulative");
				num2 = 20;
				clsReport.CloseRow();
				num2 = 21;
				int num4;
				if (DateTime.Compare(DateAndTime.Now.Date, dateTime) > 0)
				{
					num2 = 22;
					num4 = (wordTargetEndDate - DateAndTime.Now.Date).Days;
					num2 = 23;
					dateTime = DateAndTime.Now.Date;
				}
				else
				{
					num2 = 25;
					num4 = (wordTargetEndDate - dateTime).Days + 1;
				}
				num2 = 26;
				int num5 = num3 - wordCountStart;
				num2 = 27;
				int num6 = wordTarget;
				num2 = 28;
				_ = (float)((double)num5 / ((double)num6 + 0.0001));
				num2 = 29;
				int num7 = (int)Math.Round((double)(num6 - num5) / (double)num4);
				num2 = 30;
				int num8 = num4;
				int num9 = default(int);
				for (int i = 0; i <= num8; i++)
				{
					num2 = 31;
					num9 += num7;
					num2 = 32;
					clsReport.OpenRow();
					num2 = 33;
					clsReport.AddCell(Conversions.ToString(dateTime.AddDays(i).Date));
					num2 = 34;
					clsReport.AddCell(Conversions.ToString(num7));
					num2 = 35;
					clsReport.AddCell(Conversions.ToString(num9));
					num2 = 36;
					clsReport.AddCell("");
					num2 = 37;
					clsReport.AddCell("");
					num2 = 38;
					clsReport.CloseRow();
					num2 = 39;
				}
				num2 = 40;
				clsReport.CloseTable();
				num2 = 41;
				clsReport.AddFooter(App.Title);
				num2 = 42;
				clsReport.Show();
				num2 = 43;
				PrintProgressEvent?.Invoke("Printing Complete");
				num2 = 44;
				clsShared.cSubs.NormalMouse();
			}
			catch (Exception obj) when ((num != 0) & (num10 == 0))
			{
				ProjectData.SetProjectError((Exception)obj);
				/*Error near IL_0411: Could not find block for branch target IL_03dd*/;
			}
			if (num10 != 0)
			{
				ProjectData.ClearProjectError();
			}
		}
	}
}
